#ifndef TIMER_H
#define TIMER_H

#include <functional>
#include <memory>

typedef std::function<void()> TimerTask;

class Timer
{
public:
    Timer(uint32_t id, int64_t m_when_ms, int64_t m_interval_ms, const TimerTask& task);
    void run();
    uint32_t getId() const {
        return m_id;
    }
    int64_t getWhenMs() const {
        return m_when_ms;
    }
    bool getRepeated() const {
        return m_repeated;
    }
    void updateWhenTime(){
        m_when_ms += m_interval_ms;
    }
private:
    uint32_t m_id;          //id
    TimerTask m_task;       //任务函数
    int64_t m_when_ms;
    uint32_t m_interval_ms;
    bool m_repeated;
};

using TimerPtr = std::shared_ptr<Timer>;
#endif // TIMER_H
